package com.example.smart_city_0829;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.MenuItem;

import com.example.smart_city_0829.base.BaseActivity;
import com.example.smart_city_0829.base.BaseFragment;
import com.example.smart_city_0829.mainFragment.AllServeFragment;
import com.example.smart_city_0829.mainFragment.FuPinFragment;
import com.example.smart_city_0829.mainFragment.MainFragment;
import com.example.smart_city_0829.mainFragment.MineFragment;
import com.example.smart_city_0829.mainFragment.NewsFragment;
import com.example.smart_city_0829.mainFragment.adapter.FragmentViewPagerAdapter;
import com.google.android.material.bottomnavigation.BottomNavigationView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends BaseActivity {

    private BottomNavigationView bnv;
    private ViewPager vp;
    private final List<BaseFragment> mainFragments = new ArrayList<>();

    @Override
    protected int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    protected void initView() {
        bnv = (BottomNavigationView) findViewById(R.id.bnv);
        vp = (ViewPager) findViewById(R.id.vp);
    }

    @Override
    protected void initData() {
        mainFragments.add(new MainFragment());
        mainFragments.add(new AllServeFragment());
        mainFragments.add(new FuPinFragment());
        mainFragments.add(new NewsFragment());
        mainFragments.add(new MineFragment());

        vp.setAdapter(new FragmentViewPagerAdapter(getSupportFragmentManager(),mainFragments));
    }

    @Override
    protected void initEvent() {
        bnv.setOnItemSelectedListener((BottomNavigationView.OnNavigationItemSelectedListener) item -> {
            switch (item.getItemId()) {
                case R.id.home:
                    vp.setCurrentItem(0);
                    break;
                case R.id.all:
                    vp.setCurrentItem(1);
                    break;
                case R.id.fupin:
                    vp.setCurrentItem(2);
                    break;
                case R.id.news:
                    vp.setCurrentItem(3);
                    break;
                case R.id.mine:
                    vp.setCurrentItem(4);
                    break;
            }
            return true;
        });
    }

    @Override
    protected String getActionBarTitle() {
        return "null";
    }
}